package cn.zebra.dev.mall.module.shop.controller;

import cn.zebra.dev.common.restful.Result;
import cn.zebra.dev.mall.module.shop.vo.ApplyVO;
import cn.zebra.dev.member.module.login.service.SecurityMemberService;
import cn.zebra.dev.other.module.shopapply.entity.ShopApplyEntity;
import cn.zebra.dev.other.module.shopapply.service.ShopApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.time.LocalDateTime;

/**
 * @Author feifeijunxin
 * @Date 2020/5/12 10:32
 * @Version 1.0
 */
@Api(tags = "店铺申请")
@RestController
@RequestMapping("/shop/apply")
public class ShopApplyController {

    @Autowired
    private SecurityMemberService securityMemberService;

    @Autowired
    private ShopApplyService shopApplyService;

    @PostMapping("/save")
    @ApiOperation("店铺申请")
    public Result save(@Valid @RequestBody ApplyVO vo) {
        ShopApplyEntity entity = new ShopApplyEntity();
        BeanUtils.copyProperties(vo, entity);
        entity.setCreateTime(LocalDateTime.now());
        entity.setState(0L);
        entity.setUserId(securityMemberService.getMemberId());
        if (shopApplyService.save(entity)) {
            Result.error("申请已提交");
        }
        return Result.error("申请提交失败!");
    }

}
